<?php
if($_POST['submit_faq']!=true) echo '';
else {
  $faq = addslashes(trim(htmlspecialchars($_POST['faq_name'])));
  $descr = addslashes(trim(htmlspecialchars($_POST['faq_descr'])));;
  
  if(empty($faq) || empty($descr)){
	 echo '<p class="error">Моля, попълнете ВСИЧКИ полета!</p>';
  } else {
	 $sel_m = mysql_query('SELECT vupros FROM faq WHERE vupros = "'.$faq.'" AND faq_id != '.$_GET['id'].'');
	 if(mysql_num_rows($sel_m) != 0){
		echo '<p class="error">FAQ съществува!</p>';
	 } else {
		if(strlen($faq)<3 || strlen($descr)<3){
		   echo '<p class="error">Кратко име и/или описание и/или FAQ</p>';
		} else {
		   $update='UPDATE faq SET vupros="' . $faq. '", otgovor="'. $descr . '" WHERE faq_id='.$_GET['id'].'';
		   $res_update=mysql_query($update);
		   echo '<p class="success">Успешно обновяване!</p>';
		   echo '<meta http-equiv="refresh" content="1;url=editfaq.php">';
		} 
	 }
  }
}
?>